<?php
defined('IN_IXDCW') or exit('Access Denied');
/**
 * 摇奖每周记录日志
 * @author  Sameal
 */
class ErnieStatistics extends BasicModule {

	/** @var 模块id */
	private $_moduleid;

	/** @var 条目ID */
	private $_id;

	/** @var string 表格 */
	private $_table;

	/** @var string 表格数据 */
	private $_tableData;

	/** @var 是否内容分表 */
	private $_split;

	/** @var array 可用字段 */
	private $_fields;


	/**
	 * constructor
	 * @param $moduleid
	 */
	function __construct() {
		parent::__construct();
		global $prize_data_log, $MOD;
		$this->_table     = $prize_data_log;
		$this->_split     = $MOD['split'];
		$this->_fields = array('id','date','name','used','mount','printmoney');
    }
	public function setid($id) {
		$this->_id = $id;
	}

	public function getid() {
		return $this->_id;
	}

	public function getFields() {
		return $this->_fields;
	}

	/**
	 * 是否通过插入检测
	 * @param $post
	 * @return bool
	 */
	function pass($post) {
		if(!is_array($post)) return false;

		return true;
	}

	/**
	 * 设置符合内容的值
	 * @param $post
	 * @return array|mixed
	 */
	function set($post) {
		global $MOD, $DT_TIME;

		return $post;
	}
	/**
	 * 获取一条数据
	 * @return array|void
	 */
	function getOne($condition) {
		if($condition){
			return $this->_db->getOne("SELECT * FROM {$this->_table}  WHERE {$condition}");
		}else{
			return $this->_db->getOne("SELECT * FROM {$this->_table}  WHERE id=$this->_id");
		}
	}

	/**
	 * 获取列表
	 * @param string $condition
	 * @param string $order
	 * @param string $cache
	 * @return array
	 */
	function getList($condition = '', $order = 'date DESC', $cache = '') {
		global $items;
		$num = $this->_db->count($this->_table, $condition, $cache);
		$items=$num;
		$this->_pn->recordsPerPage($this->_pagesize);
		$this->_pn->records($num);
		$sql = "SELECT * FROM {$this->_table}";
		$sql .= $condition ? " WHERE {$condition}" : '';
		$sql .= $order ? " ORDER BY {$order}" : '';
		$sql .= " LIMIT " . ($this->_pn->getPage() - 1) * $this->_pagesize . ',' . $this->_pagesize;
		$lists = $catids = $CATS = array();
		$result = $this->_db->query($sql, $cache);

		while($r = $this->_db->fetchArray($result)) {
			$lists[] = $r;
		}
		return $lists;
	}

	/**
	 * 添加数据
	 * @param $post
	 */
	function add($post) {
		global $MOD,$_userid;
		$post = $this->set($post);
		$this->_db->query(Sql::insert($this->_table, $post));
		$this->_id = $this->_db->insertId();
		return $this->_id;
	}


}
